home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / C and C++ / Gnuplot 3.5 for Macintosh / SOURCES 3.5 / eval.c < prev    next >
Text File  |  1993-11-12  |  5KB  |  186 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: eval.c%v 3.50 1993/07/09 05:35:24 woo Exp $";
  3. #endif
  4.  
  5.  
  6. /* GNUPLOT - eval.c */
  7. /*
  8.  * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software is provided "as is" without express or implied warranty.
  21.  * 
  22.  *
  23.  * AUTHORS
  24.  * 
  25.  *   Original Software:
  26.  *     Thomas Williams,  Colin Kelley.
  27.  * 
  28.  *   Gnuplot 2.0 additions:
  29.  *       Russell Lang, Dave Kotz, John Campbell.
  30.  *
  31.  *   Gnuplot 3.0 additions:
  32.  *       Gershon Elber and many others.
  33.  * 
  34.  * There is a mailing list for gnuplot users. Note, however, that the
  35.  * newsgroup 
  36.  *    comp.graphics.gnuplot 
  37.  * is identical to the mailing list (they
  38.  * both carry the same set of messages). We prefer that you read the
  39.  * messages through that newsgroup, to subscribing to the mailing list.
  40.  * (If you can read that newsgroup, and are already on the mailing list,
  41.  * please send a message info-gnuplot-request@dartmouth.edu, asking to be
  42.  * removed from the mailing list.)
  43.  *
  44.  * The address for mailing to list members is
  45.  *       info-gnuplot@dartmouth.edu
  46.  * and for mailing administrative requests is 
  47.  *       info-gnuplot-request@dartmouth.edu
  48.  * The mailing list for bug reports is 
  49.  *       bug-gnuplot@dartmouth.edu
  50.  * The list of those interested in beta-test versions is
  51.  *       info-gnuplot-beta@dartmouth.edu
  52.  */
  53.  
  54. #include <stdio.h>
  55. #include "plot.h"
  56. #ifdef THINK_C
  57. #include "tout_protos.h"
  58. #endif
  59.  
  60. extern int c_token;
  61. extern struct ft_entry ft[];
  62. extern struct udvt_entry *first_udv;
  63. extern struct udft_entry *first_udf;
  64. extern struct at_type at;
  65. extern struct lexical_unit token[];
  66.  
  67. struct value *Ginteger();
  68.  
  69.  
  70.  
  71. struct udvt_entry *
  72. add_udv(t_num)  /* find or add value and return pointer */
  73. int t_num;
  74. {
  75. register struct udvt_entry **udv_ptr = &first_udv;
  76.  
  77.     /* check if it's already in the table... */
  78.  
  79.     while (*udv_ptr) {
  80.         if (equals(t_num,(*udv_ptr)->udv_name))
  81.             return(*udv_ptr);
  82.         udv_ptr = &((*udv_ptr)->next_udv);
  83.     }
  84.  
  85.     *udv_ptr = (struct udvt_entry *)
  86.       alloc((unsigned long)sizeof(struct udvt_entry), "value");
  87.     (*udv_ptr)->next_udv = NULL;
  88.     copy_str((*udv_ptr)->udv_name,t_num);
  89.     (*udv_ptr)->udv_value.type = INTGR;    /* not necessary, but safe! */
  90.     (*udv_ptr)->udv_undef = TRUE;
  91.     return(*udv_ptr);
  92. }
  93.  
  94.  
  95. struct udft_entry *
  96. add_udf(t_num)  /* find or add function and return pointer */
  97. int t_num; /* index to token[] */
  98. {
  99. register struct udft_entry **udf_ptr = &first_udf;
  100.  
  101.     int i;
  102.     while (*udf_ptr) {
  103.         if (equals(t_num,(*udf_ptr)->udf_name))
  104.             return(*udf_ptr);
  105.         udf_ptr = &((*udf_ptr)->next_udf);
  106.     }
  107.      *udf_ptr = (struct udft_entry *)
  108.       alloc((unsigned long)sizeof(struct udft_entry), "function");
  109.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  110.     (*udf_ptr)->definition = NULL;
  111.     (*udf_ptr)->at = NULL;
  112.     copy_str((*udf_ptr)->udf_name,t_num);
  113.     for(i=0; i<MAX_NUM_VAR; i++)
  114.         (void) Ginteger(&((*udf_ptr)->dummy_values[i]), 0);
  115.     return(*udf_ptr);
  116. }
  117.  
  118. #ifdef THINK_C
  119. union argument *add_action(enum operators sf_index)
  120. #else
  121. union argument *
  122. add_action(sf_index)
  123. enum operators sf_index;        /* index of p-code function */
  124. #endif
  125. {
  126.     if (at.a_count >= MAX_AT_LEN)
  127.         int_error("action table overflow",NO_CARET);
  128.     at.actions[at.a_count].index = sf_index;
  129.     return(&(at.actions[at.a_count++].arg));
  130. }
  131.  
  132.  
  133. int standard(t_num)  /* return standard function index or 0 */
  134. {
  135. register int i;
  136.     for (i = (int)SF_START; ft[i].f_name != NULL; i++) {
  137.         if (equals(t_num,ft[i].f_name))
  138.             return(i);
  139.     }
  140.     return(0);
  141. }
  142.  
  143.  
  144.  
  145. execute_at(at_ptr)
  146. struct at_type *at_ptr;
  147. {
  148. register int i,index,count,offset;
  149.  
  150. #ifdef THINK_C
  151.     static long call_count=0,ccmax=0;
  152.  
  153.     if(++call_count >(long) 60) {
  154.         fprintf(stderr," Nesting becomes too deep. %ld\n",call_count);
  155.         exit(0);
  156.     }
  157. #endif
  158.  
  159.     count = at_ptr->a_count;
  160.     for (i = 0; i < count;) {
  161.         index = (int)at_ptr->actions[i].index;
  162.         offset = (*ft[index].func)(&(at_ptr->actions[i].arg));
  163.         if (is_jump(index))
  164.             i += offset;
  165.         else
  166.             i++;
  167.     }
  168. #ifdef THINK_C
  169.      call_count--;
  170. #endif
  171. }
  172.  
  173. /*
  174.  
  175.  'ft' is a table containing C functions within this program. 
  176.  
  177.  An 'action_table' contains pointers to these functions and arguments to be
  178.  passed to them. 
  179.  
  180.  at_ptr is a pointer to the action table which must be executed (evaluated)
  181.  
  182.  so the iterated line exectues the function indexed by the at_ptr and 
  183.  passes the address of the argument which is pointed to by the arg_ptr 
  184.  
  185. */
  186.